<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<!DOCTYPE html>
<html>
<head>
    <title>医疗机构生成订单 （医疗机构端）</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <style type="text/css">
	    .overlay {
           background-color:gray;
   		   height: 500px;
           left: 100px;
           position: fixed;
           top: 10px;
           width: 2000px;
           z-index: 2147483647;
	    }
    </style>

</head>
<body class="skin-blue sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
    </section>
    
    <section class="content">
        <div class=" box box-success ">
            
            <form id="form" class="form-horizontal" action="submitOrder.html" method="post">
                <input type="hidden" id="recpAddrId" name="recpAddrId" value="${address.recpAddrId}" />
                <input type="hidden" id="plans" name="plans" />
                <input type="hidden" id="confirm" name="confirm" />
                
                <div class="box-body">
                    
                     
                    <div class="form-group form-group-xs">
                        <label for="recpAddr" class="col-sm-2 text-right">收货地址：</label>
                        <div class="col-sm-8">
                             <input class="form-control" id="recpAddr"  value="${address.recpAddr}" placeholder="收货地址"  type="hidden" ><c:out value="${address.recpAddr}"></c:out>
                        </div>
                    </div>
		     <%-- 
		            <div class="form-group form-group-xs">
		                <label for="inputTextAlter4" class="col-sm-2 text-right" ><span class="required">*</span>订单时间：</label>
		                <div class="col-sm-3">
		                     <input id="startTime" name="startTime" class="form-control" type="text" placeholder="yyyy-MM-dd" data-provide="datepicker" data-date-fmt="yyyy-MM-dd" />
		                </div>
		                <div class="col-sm-1" align="center">-</div>
		                <div class="col-sm-3">
		                     <input id="endTime" name="endTime" class="form-control" type="text" placeholder="yyyy-MM-dd" data-provide="datepicker" data-date-fmt="yyyy-MM-dd" />
		                </div>
		            </div>--%>
		            <div class="form-group form-group-xs">
                        <input type="hidden" id=isUrgent name="isUrgent" value="0">
                         <label for="inputTextAlter4" class="col-sm-2 text-right" >是否紧急：</label>
                        <div class="col-sm-9">
                        <img id="statusSelect" src="${ctx }/lib/img/rule/n.png" style="vertical-align: middle;"><span style="margin-left: 4px;">紧急</span>
                         </div>
				     </div> 
		             <div class="form-group form-group-xs">
		                <label for="inputTextAlter4" class="col-sm-2 text-right" >备注：</label>
		                <div class="col-sm-9">
		                     <textarea id="remark" name="remark" class="form-control" rows="3" maxlength="170" placeholder="备注"></textarea>
		                </div>
		            </div>
                    
                </div>
                
                <div class="box-footer text-center">
                    <button type="button" class="btn btn-success btn-sm" onclick="saveCreateOrder();">提交订单</button>
                </div>
            </form>
        </div>
    </section>
    
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
	    var dialog = top.dialog.get(window);
		var list = dialog.data; // 获取对话框传递过来的数据
    	$("#plans").val(list.array || "");
		
		
		function showOverlay() {
			top.$("body").append("<div id='MyZZdiv' style='text-align:center;height: 1000px;left: 10px; position: fixed;top: 10px;width: 1500px; z-index: 33333;'></div>").append("<div id='MyZZDivUp' style='background:url(\"${ctx }/lib/img/loading.gif\");background-repeat: no-repeat;position: fixed;height:500px;width: 500px;left: 48.3%; top: 35%;z-index: 999999999;'></div>");
		}
		function hideOverlay() {
			top.$("#MyZZdiv").remove();
			top.$("#MyZZDivUp").remove();
		}

		$("#statusSelect").click(function(){
			if("1" == $("#isUrgent").val()){
				$("#statusSelect").attr("src","${ctx }/lib/img/rule/n.png");
				$("#isUrgent").val("0");
			}else{
				$("#statusSelect").attr("src","${ctx }/lib/img/rule/y.png");
				$("#isUrgent").val("1");
			}
		})
		$(function(){
			var day = "${configValue}";
			var date =  new Date();
			var lastDate = date.getFullYear()+"-"+FormatMonth((date.getMonth()+1))+"-"+FormatDate(date.getDate());
			date.setDate(date.getDate()+Number(day));
			var nowDate = date.getFullYear()+"-"+FormatMonth((date.getMonth()+1))+"-"+FormatDate((date.getDate()));
			$('#startTime').val(lastDate);
			$('#endTime').val(nowDate);
		});
		
		function FormatMonth(month){
			 if (month >= 1 && month <= 9) {
			        month = "0" + month;
			    }
			 return month;
		}
		function FormatDate(strDate){
			 if (strDate >= 0 && strDate <= 9) {
			        strDate = "0" + strDate;
			    }
			 return strDate;
		}
		
		
	    function selectAddressList() {
	        var url = "${ctx}/createOrder/toCreateOrderAddress.html?id=" + $("#recpAddrId").val();
	        $.HN.dialog.open({
	            "id": "selectAddressList", 
	            "title": "地址选择列表", 
	            "url": url, 
	            "data": {}, 
	            "width": 800, 
	            "height": 400, 
	            "closefunc":function(address) {
	                if (address) {
	                    $("#recpAddrId").val(address.recpAddrId);
	                    $("#recpAddr").val(address.recpAddr);
	                }
	            }
	        });
	    }
	    
	    
	    function saveCreateOrder() {
	        if (!validate()) {
	            return;
	        }
	        $.HN.message.confirm("确定提交吗？", "提示信息", "确定").on(function(bool) {
	            if (bool) {
	            	 showOverlay();
	            	 submitOrder(0);
	            }
	        });
	    }
	    
	    function submitOrder(confirm) {
	    	$("#confirm").val(confirm);
            $("#form").ajaxSubmit({ 
                dataType : "json",
                timeout: 10000,
                success : function(result, statusText) {
                    if (result.success) {
                    	hideOverlay();
                        $.HN.message.alert("提交成功！", "消息", "success", function() {
                            top.mainframe.document.location = "${ctx}/purOrderInfo/toHospOderInfo.html";
                        });
                    } else if (result.code == 10001) {
                    	hideOverlay();
                        $.HN.message.alert("购物计划已提交，请勿重复提交！", "消息", "error");
                    } else if (result.code == 10002) {
                    	hideOverlay();
                        $.HN.message.confirm("部分购物计划已提交，确定提交剩余购物计划吗？", "提示信息", "确定").on(function(bool) {
                            if (bool) {
                            	showOverlay();
                            	submitOrder(1);
                            }
                        });
                    } else {
                    	hideOverlay();
                        $.HN.message.alert(result.msg || "提交失败！", "消息", "error");
                    }
                }
            });
	    }
        
        function validate() {
            
            var recpAddr = $.trim($("#recpAddr").val());
            if (recpAddr == null || recpAddr == "") {
                $.HN.message.alert("收货地址不能为空！", "消息", "warn");
                return false;
            }

            
            var remark = $.trim($("#remark").val());
            if (remark != null || remark != "") {
            	if(remark.length > 170 ){
            		 $.HN.message.alert("备注信息最大长度为170个字！", "消息", "warn");
                     return false;
            	}
            }
          /*   var startTime = $.trim($("#startTime").val());
            if (startTime == null || startTime == "") {
                $.HN.message.alert("请选择订单开始时间！", "消息", "warn");
                return false;
            } else if (startTime < new Date().format("yyyy-MM-dd")) {
            	$.HN.message.alert("订单开始时间不能小于当前时间！", "消息", "warn");
                return false;
            }
            
            var endTime = $.trim($("#endTime").val());
            if (endTime == null || endTime == "") {
                $.HN.message.alert("请选择订单结束时间！", "消息", "warn");
                return false;
            }
            
            if(startTime > endTime) {
                $.HN.message.alert("订单开始时间应该小于等于结束时间！", "消息", "warn");
                return false;
            } */
            
            return true;
        }
    
    </script>
    
</body>
</html>
